/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.treeeditpart;

import java.beans.PropertyChangeListener;

import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.uml2.uml.ClassifierTemplateParameter;
import org.eclipse.uml2.uml.ConnectableElementTemplateParameter;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.OperationTemplateParameter;

import com.cea.papyrus.core.editor.ModelManager;

/**
 * 
 * 
 * @author Patrick Tessier
 * 21 juin 06
 */

public class TemplateParameterTreeEditPart extends ElementTreeEditPart
implements PropertyChangeListener {
	

	/**
	 * Create a new instance of this edit part using the given model element.
	 * 
	 * @param modelManager 
	 * @param model a non-null ShapesDiagram instance
	 */
	public TemplateParameterTreeEditPart(org.eclipse.uml2.uml.TemplateParameter model,ModelManager modelManager) {
		super(model,modelManager);
		
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.Newtree.NamedElementTreeEditPart#getText()
	 */
	 /**
	 * 
	 * 
	 * @return 
	 */
	@Override
	public String getText() {
			String label ;
			if (getTemplateParameter() instanceof ClassifierTemplateParameter)
				label = " (ClassifierTemplateParameter)" ;
			else if (getTemplateParameter() instanceof OperationTemplateParameter)
				label = " (OperationTemplateParameter)" ;
			else if (getTemplateParameter() instanceof ConnectableElementTemplateParameter)
				label = " (ConnectableElementTemplateParameter)" ;
			else
				label = " (TemplateParameter)" ;
			String parameteredElementName = "" ;
			
			if (getTemplateParameter().getParameteredElement() != null) {
				NamedElement parameteredElement = (NamedElement)getTemplateParameter().getParameteredElement() ;
				parameteredElementName = parameteredElement.getName() ;
			}
			else {
				parameteredElementName = "<UNDEFINED>" ;
			}
			
			label = parameteredElementName + label;
			
			return label;
	 }

/**
 * 
 * 
 * @return the classifier template parameter that is linked to this editPart
 */
	public org.eclipse.uml2.uml.TemplateParameter getTemplateParameter(){
		return (org.eclipse.uml2.uml.TemplateParameter)element;
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.editpart.GraphNodeWithSemanticEditPart#activate()
	 */
	@Override
	public void activate()
	{
		if (isActive()) {
			return;
		}

		if (getTemplateParameter().getParameteredElement()!=null) {
			((Notifier)getTemplateParameter().getParameteredElement()).eAdapters().add(_adapter);}
		
		
		super.activate();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#deactivate()
	 */
	@Override
	public void deactivate()
	{
		if (!isActive()) {
			return;
		}

		if (getTemplateParameter().getParameteredElement()!=null) {
			((Notifier)getTemplateParameter().getParameteredElement()).eAdapters().remove(_adapter);}
		
		super.deactivate();
	}
	
}